﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using System.Windows;
using System.Windows.Media.Effects;
using System.Windows.Media;
using System.Windows.Controls;

namespace CommomFunctions
{
    public enum WorkingImage
    { 
        Begin,
        End,
        Null,
        BeginNull,
        EndNull
    }

    public class Imagens
    {
        private static Image logoUFRGS = new Image();

        protected static Image retNull = new Image();
        protected static Image inicioNull = new Image();
        protected static Image finalNull = new Image();
        protected static Image inicio = new Image();
        protected static Image final = new Image();

        public static BitmapSource loadBitmap(System.Drawing.Bitmap source)
        {
            return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
        }

        public static void createLogoInf(Image logoInf, Thickness th)
        {
            logoInf.Source = loadBitmap(CommomFunctions.Properties.CommomResources.LogoInfBlack);
            logoInf.Margin = th;//new Thickness(174, 0, 0, 19.481);
            logoInf.Stretch = Stretch.Uniform;
            logoInf.Height = 56;
            logoInf.Width = 87;
            logoInf.HorizontalAlignment = HorizontalAlignment.Left;
            logoInf.VerticalAlignment = VerticalAlignment.Bottom;
        }

        public static void createLogoUFRGS()
        {
            logoUFRGS.Source = loadBitmap(CommomFunctions.Properties.CommomResources.LogoUFRGSBlack);
            logoUFRGS.Margin = new Thickness(280.173, 0, 176.04, 21.481);
            logoUFRGS.Stretch = Stretch.Uniform;
            logoUFRGS.Height = 54.397;
            logoUFRGS.HorizontalAlignment = HorizontalAlignment.Left;
            logoUFRGS.VerticalAlignment = VerticalAlignment.Bottom;
        }

        public void loadSources()
        {
            retNull.Source = loadBitmap(CommomFunctions.Properties.CommomResources.Null);
            inicioNull.Source = loadBitmap(CommomFunctions.Properties.CommomResources.arrowUpNull);
            finalNull.Source = loadBitmap(CommomFunctions.Properties.CommomResources.arrowDownNull);
            inicio.Source = loadBitmap(CommomFunctions.Properties.CommomResources.arrowUp);
            final.Source = loadBitmap(CommomFunctions.Properties.CommomResources.arrowDown);        
        }

        public void setAlignments(WorkingImage wi, Stretch stch, VerticalAlignment va, HorizontalAlignment ha)
        {
            switch (wi)
            {
                case WorkingImage.Begin:
                    {
                        inicio.Stretch = stch;
                        inicio.VerticalAlignment = va;
                        inicio.HorizontalAlignment = ha;
                    }
                    break;
                case WorkingImage.End:
                    {
                        final.Stretch = stch;
                        final.VerticalAlignment = va;
                        final.HorizontalAlignment = ha;
                    } 
                    break;
                case WorkingImage.Null:
                    {
                        retNull.Stretch = stch;
                        retNull.VerticalAlignment = va;
                        retNull.HorizontalAlignment = ha;
                    }
                    break;
                case WorkingImage.BeginNull:
                    {
                        inicioNull.Stretch = stch;
                        inicioNull.VerticalAlignment = va;
                        inicioNull.HorizontalAlignment = ha;
                    }
                    break;
                case WorkingImage.EndNull:
                    {
                        finalNull.Stretch = stch;
                        finalNull.VerticalAlignment = va;
                        finalNull.HorizontalAlignment = ha;
                    }
                    break;
            }
        }

        public void setCollumnsAndLines(WorkingImage wi, Grid grid, int coluna, int colunaSpan, int linha, int linhaSpan)
        {
            switch (wi)
            {
                case WorkingImage.Begin: FuncoesVariadas.setaLinhasEColunas(inicio, grid, coluna, colunaSpan, linha, linhaSpan);
                    break;
                case WorkingImage.End: FuncoesVariadas.setaLinhasEColunas(final, grid, coluna, colunaSpan, linha, linhaSpan);
                    break;
                case WorkingImage.Null: FuncoesVariadas.setaLinhasEColunas(retNull, grid, coluna, colunaSpan, linha, linhaSpan);
                    break;
                case WorkingImage.BeginNull: FuncoesVariadas.setaLinhasEColunas(inicioNull, grid, coluna, colunaSpan, linha, linhaSpan);
                    break;
                case WorkingImage.EndNull: FuncoesVariadas.setaLinhasEColunas(finalNull, grid, coluna, colunaSpan, linha, linhaSpan);
                    break;
            }

        }
        protected void setVisibility(Image[] imgs, Visibility vis)
        {
            for (int i = 0; i < imgs.Count();i++ )
            {
                imgs[i].Visibility = vis;
            }
        }

        public void setNullImagesVisibility(Visibility vis)
        {
            retNull.Visibility = vis;
            inicioNull.Visibility = vis;
            finalNull.Visibility = vis;
        }

        public void setImagesVisibility(Visibility vis)
        {
            inicio.Visibility = vis;
            final.Visibility = vis;
        }


        public void setNullImagesMargins(Thickness iniTh, Thickness finalTh, Thickness retTh)
        {
            retNull.Margin = retTh;
            inicioNull.Margin = iniTh;
            finalNull.Margin = finalTh;
        }

        public static void setVisibility(WorkingImage wi, Visibility vis)
        {
            switch (wi)
            {
                case WorkingImage.Begin: inicio.Visibility = vis;
                    break;
                case WorkingImage.End: final.Visibility = vis;
                    break;
                case WorkingImage.Null: retNull.Visibility = vis;
                    break;
                case WorkingImage.BeginNull: inicioNull.Visibility = vis;
                    break;
                case WorkingImage.EndNull: finalNull.Visibility = vis;
                    break;
            }

        }

        public Visibility getVisibility(WorkingImage wi)
        {
            switch (wi)
            {
                case WorkingImage.Begin: return inicio.Visibility;
                    
                case WorkingImage.End: return final.Visibility;
                    
                case WorkingImage.Null: return retNull.Visibility;
                    
                case WorkingImage.BeginNull: return inicioNull.Visibility;
                    
                case WorkingImage.EndNull: return finalNull.Visibility;                    
            }
            return Visibility.Visible;
        }

        public Thickness getMargin(WorkingImage wi)
        {
            switch (wi)
            {
                case WorkingImage.Begin: return inicio.Margin;

                case WorkingImage.End: return final.Margin;

                case WorkingImage.Null: return retNull.Margin;

                case WorkingImage.BeginNull: return inicioNull.Margin;

                case WorkingImage.EndNull: return finalNull.Margin;
            }
            return new Thickness(0);
        }

        public Image getImage(WorkingImage wi)
        {
            switch (wi)
            {
                case WorkingImage.Begin: return inicio;

                case WorkingImage.End: return final;

                case WorkingImage.Null: return retNull;

                case WorkingImage.BeginNull: return inicioNull;

                case WorkingImage.EndNull: return finalNull;
            }
            return retNull;
        }

        public void setMargin(WorkingImage wi, Thickness th)
        {
            switch(wi)
            {
                case WorkingImage.Begin: inicio.Margin = th;
                    break;
                case WorkingImage.End: final.Margin = th;
                    break;
                case WorkingImage.Null: retNull.Margin = th;
                    break;
                case WorkingImage.BeginNull: inicioNull.Margin = th;
                    break;
                case WorkingImage.EndNull: finalNull.Margin = th;
                    break;
            }
        }

        public void setHeight(WorkingImage wi, int height)
        {
            switch(wi)
            {
                case WorkingImage.Begin: inicio.Height = height;
                    break;
                case WorkingImage.End: final.Height = height;
                    break;
                case WorkingImage.Null: retNull.Height = height;
                    break;
                case WorkingImage.BeginNull: inicioNull.Height = height;
                    break;
                case WorkingImage.EndNull: finalNull.Height = height;
                    break;
            }
        }

        /// <summary>
        /// Sets all images to hidden when the queue is destroyed
        /// </summary>
        internal static void setAllImagesHidden()
        {
            setVisibility(WorkingImage.Begin, Visibility.Hidden);
            setVisibility(WorkingImage.End, Visibility.Hidden);
            setVisibility(WorkingImage.Null, Visibility.Hidden);
            setVisibility(WorkingImage.BeginNull, Visibility.Hidden);
            setVisibility(WorkingImage.EndNull, Visibility.Hidden);
        }
    }
}
